<?php


namespace app\admin\controller\Web;

use app\admin\model\WebSwiper;
use app\admincommon\controller\AdminController;
use think\facade\View;

class Swiper extends AdminController{

    protected $webswiper;

    public function __construct()
    {
        $this->webswiper = new WebSwiper();
        
    }


    function index(){


        $lists = $this->webswiper->order("id desc")->select();

        View::assign([
            "total"=>1,
            "page"=>1,
            "lists"=>$lists
        ]);

        return View::fetch();
        
    }



    function add(){

        if(request()->isPost()){

            $post = request()->post();
            $data["imgurl"]=$post["imgurl"];
            $data["title"]=$post["title"];
            $data["sort"]=$post["sort"];
            $data["alias"]=$post["alias"];
            $data["url"]=$post["url"];
            $data["descriptions"]=$post["descriptions"];
            $data["isshow"]=$post["isshow"];
            $data["isshow"]=$post["isshow"];
            $data["create_time"]=time();
            $data["lang"]=$post["lang"];
            
            $id = $this->webswiper->insertGetId($data);
            echo json_encode(["code"=>1,"msg"=>"添加成功","id"=>$id]);

        }else{

            return View::fetch();

        }

    }

    function edit(){

        

        if(request()->isPost()){

            $post = request()->post();
            $data["id"]=$post["id"];
            $data["imgurl"]=$post["imgurl"];
            $data["title"]=$post["title"];
            $data["sort"]=$post["sort"];
            $data["alias"]=$post["alias"];
            $data["url"]=$post["url"];
            $data["descriptions"]=$post["descriptions"];
            $data["isshow"]=$post["isshow"];
            $data["lang"]=$post["lang"];
            $data["create_time"]=time();

            $this->webswiper->update($data);

            echo json_encode(["code"=>1,"msg"=>"修改成功"]);

        }else{

            $id = input("id");

            $item = $this->webswiper->where(["id"=>$id])->find()->toArray();

            View::assign(["item"=>$item]);

            return View::fetch();

        }

    }





}








?>